#include "_ctest.h"







int _ctest_add(PikaObj *self, int a, int b, int c)
{
    return a+b+c;
}



void _ctest_ctest_list(PikaObj *self, PikaObj* L)
{
    int len;
    len = pikaList_getSize(L);
    for (int i = 0; i < len; i++)
    {
        int v =pikaList_getInt(L, i);
        printf("hhhh %d \n ",v);

        if(ARG_TYPE_INT == pikaList_getType(L, i))
        {
            int v =pikaList_getInt(L, i);
            printf("int %d \n ",v);
        }
        if(ARG_TYPE_FLOAT == pikaList_getType(L, i))
        {
            float v =pikaList_getFloat(L, i);
            printf("float %f \n ",v);
        }

    }
    
}

/*forEach的回调函数*/
int32_t _test_dict_foreach
(
    PikaObj* self,
    Arg* keyEach,
    Arg* valEach,
    void* context
)
{
    char *key_str = arg_getStr(keyEach);
    
     if(ARG_TYPE_INT == arg_getType(valEach))
    {
        int key_int = arg_getInt(valEach);
        printf("key_str =  %s, key_int = %d \n ",key_str, key_int);
    }
    if(ARG_TYPE_FLOAT == arg_getType(valEach))
    {
        float key_float = arg_getFloat(valEach);
        printf("key_str =  %s, key_float = %f \n ",key_str, key_float);
    }

    return 0;
}

void _ctest_ctest_dict(PikaObj *self, PikaObj* d)
{
    //假设 已经知道了key 的名字
    int a = pikaDict_getInt(d, "a");
    double b = pikaDict_getFloat(d, "b");
    printf("a = %d ,b  = %f \n",a,b);

    /*假设不知道 ，使用forEach函数 对所有的成员进行遍历*/
    pikaDict_forEach(d, _test_dict_foreach,NULL);
}


/*创建 list 并返回*/
PikaObj* _ctest_dict_return(PikaObj *self)
{
   
    PikaObj* mydict = New_PikaDict();
    pikaDict_set( mydict, "a",  arg_newInt(1));
    pikaDict_set( mydict, "b", arg_newFloat(2.0));
    return mydict;
}

/*创建 dict 并返回*/
PikaObj* _ctest_list_return(PikaObj *self)
{
     PikaObj* mylist = New_PikaList();
    pikaList_append(mylist, arg_newInt(1)); // int
    pikaList_append(mylist, arg_newFloat(0.3)); // float
    pikaList_append(mylist, arg_newStr("333")); // str
    return mylist;
}



